The tool pyPOCQuant aims to automatically detect and quantify signal bands from lateral flow assays (LFA) or Point of Care tests (POC or POCT) from an image. It can batch analyze large amounts of images in parallel.
An analysis pipeline can be run either from the command line (good for automating large numbers of analysis) or from a desktop application.
At current stage, almost all operations are supported from the user interface, with the exception of the optional Split images by strip manufacturer step.
This only applies if you collected many images using POCTs from different vendors and stored all the images in one common folder! Analysis settings would need to be slightly adapted for different POCTs shapes and sizes.
If you have many images in an unorganized way we provide a helper script to sort them by manufacturer into subfolders.
This is currently not integrated into the user interface and needs to be run from console.
$ python ./split_images_by_strip_type_parallel.py -f /PATH/TO/INPUT/FOLDER -o /PATH/TO/OUTPUT/FOLDER -w ${NUM_WORKERS}
/PATH/TO/INPUT/FOLDER: path to the folder that contains all images for a given camera.
PATH/TO/OUTPUT/FOLDER: path where all images will be organized into subfolders; one per each strip manufactured. Strip images that cannot be recognized (or do not contain any strip) will be moved to an UNDEFINED subfolder.
AUGURIXBIOZAKCTKBIOTECHDRALBERMEXACARELUMIRATEKNTBIOSUREBIOTECHTAMIRNAPlease notice: the list of known manufacturers is defined in pyPOCQuant.consts.KnownManufacturers.
NUM_WORKERS: number of parallel processes; e.g. 8.You can prepare a default parameter file from the command line as follows:
$ python ./pypocquant/pyPOCQuant_FH.py -c /PATH/TO/INPUT/settings_file.conf
Open the file in a text editor and edit it.
max_workers=2
qc=True
verbose=True
sensor_band_names=('igm', 'igg', 'ctl')
peak_expected_relative_location=(0.25, 0.53, 0.79)
sensor_center=(178, 667)
sensor_size=(61, 249)
sensor_border=(7, 7)
perform_sensor_search=True
qr_code_border=40
subtract_background=True
sensor_search_area=(71, 259)
sensor_thresh_factor=2.0
raw_auto_stretch=False
raw_auto_wb=False
strip_try_correct_orientation=False
strip_try_correct_orientation_rects=(0.52, 0.15, 0.09)
strip_text_to_search='COVID'
strip_text_on_right=True
force_fid_search=True
Some of the parameter names contain the term
strip: this is used to indicate the POCT. The prefixsensorindicates the measurement region within thestrip.
See Explanations for detailed description of the parameters.
Please notice that some parameters are considered "Advanced"; in the user interface the parameters are separated into "Runtime parameters", "Basic parameters", and "Advanced parameters".
Open the settings file and adjust the parameters to fit your images.
Important parameters are the sensor_size, sensor_center, and sensor_search_area (the latter being an advanced parameter).
The user interface allows to easily define those parameters by drawing onto the extracted POCT image.
Sensor parameters are relative to the POCT image.
In the following we show how to obtain position and extent of the sensor areas in Fiji or ImageJ. Later we will see how to do the same in the pyPOCQuant user interface.
x=539, y=145, **w=230, h=62**.x, and y coordinates of the center, respectively, are show in Fiji's toolbar; e.g. x=*601*, y=144, value=214 (and equivalently for y).$ python pyPOCQuant_FH.py -f /PATH/TO/INPUT/FOLDER/MANUFACTURER -o /PATH/TO/RESULTS/FOLDER -s /PATH/TO/CONFIG/FILE -w ${NUM_WORKERS}
/PATH/TO/INPUT/FOLDER/MANUFACTURER: path to the folder that contains all images for a given camera and manufacturer./PATH/TO/RESULTS/FOLDER: path where the results (and the quality control images) for a given camera and manufacturer will be saved. The results are saved in a quantification_data.csv text file./PATH/TO/CONFIG/FILE: path to the configuration file to be used for this analysis. Please see below. Notice that a configuration file will be needed per manufacturer and (possibly) camera combination.NUM_WORKERS: number of parallel processes; e.g. 8.This only applies if you collected many images using POCTs from different vendors and stored all the images in one common folder! Analysis settings would need to be slightly adapted for different POCTs shapes and sizes.
Please notice that this step has not been integrated into the user interface yet, and must be run from the command line.
A settings file must not necessarily be created in advance. The Parameter Tree can be edited directly. Optionally, settings can be loaded or saved from the UI.
How to estimate sensor parameters graphically in the UI:
Select the input folder and click on one of the listed images to display it. The POCT region will be automatically extracted and shown in the view at the top. The lower view shows the whole image.
Hit the Draw sensor outline icon (red arrow) in the toolbar. This will allow you to interactively define the sensor area and the peak_expected_relative_location parameters.
| Drawing sensor by clicking into the corners | Drawing finished with aligned bars |
|---|---|
sensor_search_area is set to be 10 pixels wider and taller than the sensor_size. This can be changed in the advanced parameters (but beware to keep it only slightly larger than the sensor_size: it is meant only for small refinements).Test parameters button under the Parameter Tree.File->Save settings file)Once the previous steps are done and all parameters are correctly set, you can hit the Run button to start the analysis.
Note: a step by step guide can be found under Quick start (Help -> Quick start)
The following settings must be specified. These are default values and need to be adopted for a series of the same kind of images. Please note: in the following, strip is used to indicate the POCT, and sensor to indicate the measurement region within the strip.
max_workers=2
qc=True
verbose=True
sensor_band_names=('igm', 'igg', 'ctl')
peak_expected_relative_location=(0.25, 0.53, 0.79)
sensor_center=(178, 667)
sensor_size=(61, 249)
sensor_border=(7, 7)
perform_sensor_search=True
qr_code_border=40
subtract_background=True
sensor_search_area=(71, 259)
sensor_thresh_factor=2.0
raw_auto_stretch=False
raw_auto_wb=False
strip_try_correct_orientation=False
strip_try_correct_orientation_rects=(0.52, 0.15, 0.09)
strip_text_to_search='COVID'
strip_text_on_right=True
force_fid_search=True
True or FalseTrue when testing parameters.True or FalseTrue when testing parameters.t2, t1 and ctl (e.g., IgM, IgG and Ctl).(y, x).(height, width).(lateral, vertical).True, the (inverted) sensor is searched within sensor_search_area around the expected sensor_center; if False, the sensor of size sensor_size is simply extracted from the strip image centered at the relative strip position sensor_center.True or FalseTrueTrue, estimate and subtract the background of the sensor intensity profile (bands).True or FalseTrueThese parameters will most likely work with the default values above.
(height, width). skip_sensor_search is False.2, maybe 3.True or FalseFalseTrue or FalseFalseTrue or FalseFalse True, make sure to properly set the strip_try_correct_orientation_rects parameters below!Relative height factor, defines the relative height of the rectangles with respect to the strip. The second parameter, Relative center cut-off, defines the relative offset from the sensor center and therefore the width of the rectangle. Finally, the third parameter, Relative border cut-off, defines the relative offset from the strip's left and right borders and hence the width of the search rectangle.(0:1, 0:1, 0:1)(0.52, 0.15, 0.09)"" to skip search and correction. If the strip has some text printed on either side of the sensor, it can be searched to guess the orientation. See also strip_text_on_right.strip_text_to_search text is expected to be on the right. If strip_text_on_right is True and the text is found on the left hand-side of the strip, the strip will be rotated 180 degrees.strip_text_to_search is "".True or FalseFalseThe analysis pipeline delivers a .csv that contains a relatively large table of results. The extracted features are explained in the following.
Structure and description of the result table:
fid: patient FID in the form F5921788
fid_num: just the numeric part of the FID (i.e., 5921788)
filename: name of the analyzed image
extension: extension (either .JPG or .ARW, .CR2, .NEF)
basename: filename without extension
iso_date: date of image acquisition in the form YYYY-MM-DD (e.g. 2020-04-14)
iso_time: time of image acquisition in the form HH-MM-SS (24-h format)
exp_time: camera exposure time
f_number: aperture F number
focal_length_35_mm: 35mm equivalent focal length
iso_speed: camera ISO value
manufacturer: POCT manufacturer
plate: plate number
well: well (e.g. A 01)
ctl: 1 if the control band could be extracted, 0 otherwise.
t2: 1 if the t2 band (e.g. IgM) could be extracted, 0 otherwise.
t1: 1 if the t1 band (e.g. IgG) could be extracted, 0 otherwise.
ctl_abs: absolute signal strength of the control band,
t2_abs: absolute signal strength of the t2 band,
t1_abs: absolute signal strength of the t1 band.
ctl_ratio: relative signal strength of the control band (always 1.0 if detected)
t2_ratio: relative signal strength of the t2 band with respect to the control band
t1_ratio: relative signal strength of the t1 band with respect to the control band
issue: if issue is 0, the image could be analyzed successfully, if issue > 0 it could not. See the list of issues below
user: custom field
Note: expect small residual variations in the absolute signal strengths (
ctl_abs,t2_abs, andt1_abs) across images in a batch due to inhomogeneities in acquisition.
Each analyzed image is assigned an integer issue:
Types and examples' of quality control images:
Raw image shown as comparison:
IMAGE_FILE_NAME_aligned_box Aligned raw image
IMAGE_FILE_NAME_box : QR code box around the POCT oriented such that the control band is always on the right side.
IMAGE_FILE_NAME_rotated: Raw image rotated such that the POCT is at the parallel to the bottom side of the image.
IMAGE_FILE_NAME_strip_gray_aligned: Aligned POCT cropped around its outline such that it is parallel to the bottom side.
IMAGE_FILE_NAME_strip_gray_aligned_after_ocr Aligned POCT cropped around its outline such that it is parallel to the bottom side after OCR filtering such that the pipetting part is always left (for the cases where the POCT was not placed in the correct orientation in the template.)
IMAGE_FILE_NAME_strip_gray_hough_analysis.png Aligned POCT cropped around its outline such that it is parallel to the bottom side detecting the pipetting spot to identify wrongly oriented POCT in the strip box.
IMAGE_FILE_NAME_strip_gray_hough_analysis_candidates.png Hough analysis candidate results. The rectangles indicate the search areas while as the circles indicate potential hits for the pipetting spot. Red rectangle and magenta circles identifies the side where the pipetting spot was detected. Note it is assumed that the control band is always opposite of the pipetting area.
IMAGE_FILE_NAME_sensor: Aligned sensor crop showing the bands.
IMAGE_FILE_NAME_peak_overlays: Sensor crop with colored rectangle overlay(s) indicating the area(s) where the signal for each detected band is quantified. Notice that the rectangle extends to cover the whole area under the curve, from background level through peak and back to background level.
IMAGE_FILE_NAME_peak_background_estimation: Control figure displaying the performance of the background estimation fit. Black dashed line is a an estimation of the background level obtained by robust linear fit of the band profile. From the estimate background trend a constant value is subtracted (resulting red solid line). This is to make sure that the signal is flat after correction, but no values are clipped.
IMAGE_FILE_NAME_peak_analysis: Control figure displaying the performance of the peak analysis. Red circle indicates the max peak height. The green dashed line is an estimate of the local background that is used to test all candidate local maxima against a threshold defined by the red dashed line. This line is calculated as the (median of the background values) + f * (median deviation of the background values). The factor f is a user parameter and defaults to 2. The solid blue, orange and green line under the curves indicate the local span of each of the bands and indicate which part of the signal is integrated.
The log file contains more detailed information for each processed image identified by its file name such as Img0052.jpg.
It informs about the barcode extraction and its rotation, the QR code box rotation, the FID extraction, the actual sensor coordinates and the identified bands.
Example log:
File = IMG_8489.JPG
Processing IMG_8489.JPG
Best percentiles for barcode extraction: (0, 100); best scaling factor = 0.25; score = 6/6
File IMG_8489.JPG: best percentiles for barcode extraction after rotation: (0, 100); best scaling factor = 0.25; score = 6/6
File IMG_8489.JPG: Strip box image rotated by angle -0.9172186022623166 degrees using QR code locations.
File IMG_8489.JPG: FID = 'F5923994'
File IMG_8489.JPG: sensor coordinates = [140, 207, 523, 780], score = 1.0
Peak 69 has lower bound 48 (d = 21) with relative intensity 0.06 and upper bound 93 (d = 24) with relative intensity 0.00. Band width is 46. Band skewness is 1.14
Peak 138 has lower bound 104 (d = 34) with relative intensity 0.00 and upper bound 162 (d = 24) with relative intensity 0.10. Band width is 59. Band skewness is 0.71
Peak 203 has lower bound 170 (d = 33) with relative intensity 0.04 and upper bound 248 (d = 45) with relative intensity 0.00. Band width is 79. Band skewness is 1.36
File IMG_8489.JPG: the bands were 'normal'.
✓ File IMG_8489.JPG: successfully processed and added to results table.
A settings file is created in the -o /PATH/TO/RESULTS/FOLDER with the actually used parameters for the analysis. It can be used to reproduce the obtained results.
See settings file section for detailed description.
The GUI offers several actions via the menu, the toolbar and buttons.
File menu:
File: Lets you load ( File --> Load settings file) and save ( File --> Save settings file) a settings file
Help: Get quick instructions and open this manual
Toolbar:
Load settings from file: Load settings from file into the Parameter Tree.Save settings to file: Save current settings to file.Draw sensor outline: Activates drawing a polygon by clicking into the corners of the sensor on the images.Delete sensor: Deletes currently drawn sensor.Mirror image vertically: Mirrors the displayed image vertically.Mirror image horizontally: Mirrors the displayed image horizontally.Rotate clockwise: Rotates the displayed image clock wise.Rotate counter clockwise: Rotates the displayed image counter clock wise.Set rotation angle in degrees: Specifies the rotation angle.Zoom in: Zooms in the displayed image.Zoom out: Zooms out the displayed image .Reset zoom: Resets the zoom level.Measure distance: Lets you draw a line on the image to measure distances. It will update the qr_border_distance parameter.Show / hide console: shows or hides the console at the bottom of the UI.Select input folder: Allows to specify the input folder.
Select output folder: (Optional) Lets you select a output folder. If left empty a output subfolder is automatically generated in the input folder.
Image list: Lists all available images in the input folder. Click onto the filename to display one in 5.
Parameter Tree: Adjust parameters manually if needed.
POCT area: Shows the extracted POCT and allows for drawing the sensor.
Display area: Shows the currently selected image.
Test parameters: Runs the pipeline on the selected image with current settings. The test folder will be opened automatically to inspect the control files.
Run: Runs the pipeline with the current settings**.
Log: Informs the user about performed actions.
Tools menu:
Save POCT template: Lets you save and print the POCT template to be used for the image acquisition.
Save QR labels template Lets you save an Excel template to be used to generate QR code labels for all your samples from a list.
Generate QR labels: Lets you generate QR labels for your samples using the excel template or a csv file with a list of the names in the correct format: SAMPEID-MANUFACTURER-PLATE-WELL-USERDATA. You can use the USERDATA field for very short annotations; please make sure not to use dashes (-) in this field, but replace them with underscores (_). You can define the page size, label size, position and number per page to match the format for any printable label paper as, for instance, from AVERY.
Split images by type: helps organizing mixtures of images from different POCT manufacturers stored in one and the same folder. The tool will analyze each of the images and attempt to extract the manufacturer information from the QR code (if present) or by searching for the name on the POCT itself (OCR). If the manufacturer can be resolved, the image is moved into a sub-folder with the name of the manufacturer, otherwise it will be moved into a subfolder called UNDEFINED. As long as the QR code structure is satisfied (which is guaranteed if using the Generate QR labels tool explained above), even previously unknown manufacturers can be recognized. Should the QR code detection fail, a fall-back OCR detection can use a comma-separated list of expected manufacturer names to potentially identify unknown manufacturers. The input folder defines the folder containing all the images to process, and output folder the location where the split images should be moved. The number of cores defines the number of images that will be processed in parallel.
Help menu:
Quick instructions: Shows the quick instructions dialog.
Quick start: Opens the quick start document describing how to set up the image acquisition setup, perform the acquisition and some potential problems and their solutions one might encounter.
User manual: Opens this document.
About: About the software and its dependencies.